unit CadastroTransportadora;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFomCadastro, DBCtrls, StdCtrls, Buttons, ExtCtrls, DB, DBTables,
  Mask, DBClient, Provider, Menus, ComCtrls, Grids, DBGrids;

type
  TFCadastroTransportadora = class(TFormCadastro)
    Label1: TLabel;
    Label2: TLabel;
    DBENome: TDBEdit;
    Label5: TLabel;
    DBEPlacaVeiculo: TDBEdit;
    Label6: TLabel;
    DBEEndereco: TDBEdit;
    Label7: TLabel;
    DBECidade: TDBEdit;
    Label8: TLabel;
    DBEUf: TDBEdit;
    Label3: TLabel;
    Label13: TLabel;
    Label9: TLabel;
    DBEUFVeiculo: TDBEdit;
    DBRGTipoTransportadora: TDBRadioGroup;
    DBECpfCNPJ: TDBEdit;
    DBEInscEstadual: TDBEdit;
    DBRGFrete: TDBRadioGroup;
    cdsCadastroTRANS_CODIGO: TIntegerField;
    cdsCadastroTRANS_NOME: TStringField;
    cdsCadastroTRANS_CPFCNPJ: TStringField;
    cdsCadastroTRANS_FRETE: TStringField;
    cdsCadastroTRANS_PLACAVEICULO: TStringField;
    cdsCadastroTRANS_UFVEICULO: TStringField;
    cdsCadastroTRANS_ENDERECO: TStringField;
    cdsCadastroTRANS_CIDADE: TStringField;
    cdsCadastroTRANS_UF: TStringField;
    cdsCadastroTRANS_INSCESTDUAL: TStringField;
    cdsCadastroTRANS_TIPOTRANSPORTADORA: TStringField;
    cdsCadastroTRANS_CODIGO_CONFERENCIA: TIntegerField;
    cdsCadastroUSUARIO_CADASTRO: TStringField;
    cdsCadastroUSUARIO_AUTERACAO: TStringField;
    cdsCadastroUSUARIO_EXCLUSAO: TStringField;
    cdsCadastroDATA_CADASTRO: TDateTimeField;
    cdsCadastroDATA_EXCLUSAO: TDateTimeField;
    cdsCadastroDATA_AUTERACAO: TDateTimeField;
    cdsCadastroEXCLUIDO: TStringField;
    cdsCadastroUSUARIO: TStringField;
    cdsCadastroDATAMODIFICACAO: TDateTimeField;
    cdsCadastroUSUARIO_RECUPERACAO: TStringField;
    cdsCadastroDATA_RECUPERACAO: TDateTimeField;
    DBEdit1: TDBEdit;
    procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
    procedure BtnIncluirClick(Sender: TObject);
    procedure BtnSalvarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BtnConsutaClick(Sender: TObject);
    procedure DBRGTipoTransportadoraClick(Sender: TObject);
    procedure DBECpfCNPJKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBEUfKeyPress(Sender: TObject; var Key: Char);
    procedure cdsCadastroAfterOpen(DataSet: TDataSet);
  private
    { Private declarations }
   procedure ColocaMascara;
  public
    { Public declarations }
  end;

var
  FCadastroTransportadora: TFCadastroTransportadora;

implementation

uses UGeral, PesquisaTransportadora;

{$R *.dfm}
procedure TFCadastroTransportadora.ColocaMascara;
begin
 // cdsCadastro.FieldByName('TRANS_INSCESTDUAL').EditMask := inscEstadual;
  cdsCadastro.FieldByName('TRANS_CPFCNPJ').EditMask     := CPF;
end;



procedure TFCadastroTransportadora.DBNavigator1Click(Sender: TObject;
  Button: TNavigateBtn);
begin
  inherited;
  DBRGTipoTransportadoraClick(Sender);
end;

procedure TFCadastroTransportadora.BtnIncluirClick(Sender: TObject);
begin
  inherited;
  cdsCadastro.FieldByName('TRANS_CODIGO').AsInteger             := Retorna_Codigo_Generetor('GEN_TRANSPORTADORA');
  cdsCadastro.FieldByName('TRANS_TIPOTRANSPORTADORA').AsInteger :=1;
  cdsCadastro.FieldByName('TRANS_FRETE').AsInteger              :=1;
  DBENome.SetFocus;

end;

procedure TFCadastroTransportadora.BtnSalvarClick(Sender: TObject);
begin

  if DBENome.Text = '' then
  begin
    ShowMessage('Campo Nome tem que ser preenchido !');
    exit;
  end;

  inherited;

end;

procedure TFCadastroTransportadora.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  FCadastroTransportadora.Release;
  FCadastroTransportadora:=nil;
  inherited;
end;

procedure TFCadastroTransportadora.BtnConsutaClick(Sender: TObject);
begin
  inherited;
  {
  Application.CreateForm(TFPesquisaTransportadora, FPesquisaTransportadora);
  FPesquisaTransportadora.Show;
  Self.Enabled:=False;
  }
end;

procedure TFCadastroTransportadora.DBRGTipoTransportadoraClick(
  Sender: TObject);
begin
  inherited;
 case DBRGTipoTransportadora.ItemIndex of
  0 :  Begin
        Label3.Caption:='CPF';
        cdsCadastro.FieldByName('TRANS_CPFCNPJ').EditMask:=CPF ;
        DBECpfCNPJ.Width:=110;
       end;
  1 :  begin
        Label3.Caption:='CNPJ';
        cdsCadastro.FieldByName('TRANS_CPFCNPJ').EditMask:=CNPJ;
        DBECpfCNPJ.Width:=112;
       end;
 end;

end;

procedure TFCadastroTransportadora.DBECpfCNPJKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
 if key in [8,46] then
  TDBEdit(sender).EditText:='';
end;

procedure TFCadastroTransportadora.DBEUfKeyPress(Sender: TObject;
  var Key: Char);
begin
  inherited;
 if (key in ['0'..'9']) then
  key:=#0;
end;

procedure TFCadastroTransportadora.cdsCadastroAfterOpen(DataSet: TDataSet);
begin
  inherited;
  ColocaMascara;

end;

end.
